<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>商品评价列表页 - ${web.name}${web.additionalTitle!}</title>
<link href="${root}/u/css/product.css" type="text/css" rel="stylesheet" />
<link href="${root}/u/css/pshow.css" type="text/css" rel="stylesheet" />
<link href="${root}/u/css/common.css" type="text/css" rel="stylesheet" />
<script language="JavaScript" type="text/javascript" src="${root}/u/js/jquery.js"></script>
<script type="text/javascript">
 function discuss(productId,memberId){
     $.post("haveDiscuss.jspx",{productId:productId},function(data){
            if(data=='success'){
                $("#discussTextArea").css("display","");
                $("#writeDiscuss").css("display","none");
                $("#button1").css("display","");
            }else if(data=='denru'){
                alert('您还没有登陆，请先登录');
                var loginForm=getLoginForm();
                loginForm.submit();
            }else if(data=='false'){
                alert('必须购买过该产品才能够评论!');
            }else if(data=='updateDiscuss'){
            	alert("您已经评价过该商品")
                $("#button1").text("更改评论");
            	$("#writeDiscuss").css("display","none");
            	$("#updateDiscuss").css("display","");
            	$("#discussTextArea").css("display","");
            }
     });
}

 function getLoginForm(){
     return document.getElementById("loginForm");
 }
 function saveOrUpdateDiscuss(productId,storeId){
	 var disContent=$("#disContent").val();
	 var discussType = 0;    //获取评价类型
     var chkObjs = document.getElementsByName("discussType");
     for(var i=0;i<chkObjs.length;i++){
          if(chkObjs[i].checked){
              discussType = chkObjs[i].value;
              break;
          }
     }
     $.post("saveOrUpdateDiscuss.jspx",{
    	 productId:productId,storeId:storeId,disContent:disContent,discussType:discussType
    	 },function(data){
	    	 if(data=='success'){
	          alert("评论成功");
	       	  getTableForm().submit();   //用户评论成功后，刷新页面
	         }else if(data=="false"){
	        	 alert('您还没有登陆，请先登陆');
	             var loginForm=getLoginForm();
	             loginForm.submit();
	         }else if(data=="updateSuccess"){
	        	 alert("更改评论成功");
		       	  getTableForm().submit();
	         }
         }              
	 )
}

 function getTableForm(){
     return document.getElementById("tbc_10");
 }
 
function g(o){
	return document.getElementById(o);
}

function HoverLi(m,n){
	//jQuery
	$(".spms_curr").attr("className","spms_normal");
	$(".dis").attr("className","undis")
	
	//javascript
	g('tb_'+m+n).className='spms_curr';
	g('tbc_'+m+n).className='dis';
	
}  
 
</script>
</head>
<style>
.pl_line { width:930px; font-size:12px;}
.pl_zone {color: #000000; display: block; line-height: 24px; overflow-x: hidden; overflow-y: hidden; word-wrap: break-word; border-bottom: #EAEAEA dotted 1px; padding: 10px; }
.pl_zone span {color: #999999;}
UL, LI {list-style-image: none; list-style-position: outside; list-style-type: none; margin:0; padding: 0;}
.pl_txt {color: #333333; line-height: 22px;}
.clear10{ height:10px; clear:both;}
.pageNumber{
	line-height:35px;
	text-align:center;
	clear:both;
	margin:10px auto;
	}	
</style>
<body>
<div id="writeDiscuss">
	<div class="w930">
    	<div style="color:#666666;">商品评价</div>
        <div class="clear10"></div>
        <div class="haopingshu">
		[@discuss_count productId=product.id]
			[#assign count=discusses?size]
                [@discuss_count productId=product.id discussType='1']
					[#assign typeCount=discusses?size]
					[#if count!=0]
						[#assign percent=(typeCount / count)]
						  <h1>${percent*100 }%</h1>							 
					[#else]
						  <h1>0</h1>	
					[/#if]
				[/@discuss_count]
		[/@discuss_count]
            <h2>好评度</h2>
        </div>
        <div class="w490">
        	<div style="text-align:center; line-height:65px; margin:auto;">本商品暂无点评，请购买成功后发表评论！</div>
        </div>
        <div class="dianping">
        	您可对已购商品进行评价
            <div class="clear10"></div>
        	<a href="javascript:void(0)" style=" background:#42b312; color:#fff; text-align:center; width:100px; height:30px; line-height:30px; font-size:18px; margin:auto; display:block;" onclick="discuss('${product.id!}','[#if member??]${member.id}[/#if]');">写评论 </a>
        </div>
    </div>
    <div class="clear10"></div>
</div>

<div id="updateDiscuss" style="display:none"><font color="purple">更改评论</font></div>

<div id="discussTextArea" style="display:none">
    <input type="hidden" name="memberId" value="" />
    <p>评价：
    [#list discussTypes as d]
    <input type="radio"  name="discussType" value="${d.value}" checked="checked"/>${d.name}&nbsp;&nbsp;
    [/#list]
    <p>
    <textarea rows="6" cols="50" id="disContent" ></textarea>
    <button id="button1" onclick="saveOrUpdateDiscuss('${product.id}','[#if product.store??]${product.store.id}[/#if]');">  发表评论</button>
    <input id="productId"type="hidden" name="productId" value="${product.id}"/>
</div>
 <!-- 2015.02.16 如果后台能够将member对象传递过来，就可以模仿亚马逊的更改评论功能。 -->
 
<!-- 模仿商品咨询列表页，用数据字典对评价类型进行后台维护 -->
<div class="spxx_type">
<ul>
[@discuss_count productId=product.id]
<li class="spms_curr" id="tb_10" onclick="HoverLi(1,0)"style="cursor: hand"><a>全部(${discusses?size})</a></li>	
[/@discuss_count]

[#list discussTypes as d]
[@discuss_count productId=product.id discussType=d.value]
<li class="spms_normal" id="tb_1${d.value}" onclick="HoverLi(1,${d.value})" style="cursor: hand"><a>${d.name}(${discusses?size})</a></li>
[/@discuss_count]
[/#list]	
</ul>
</div>

<form id="tbc_10" class="dis"action="searchDiscussPage.jspx" method="post">
<input type="hidden" name="productId" value="${product.id}"/>
[@discuss_page productId=product.id count='20' pageNo=pageNo ]
<div class="pl_line "> 
    <ul class="pl_zone">
    [#if tag_list?size gt 0]
    [#list tag_list as discuss]
    <li><strong>${discuss.member.username!}</strong>&nbsp;&nbsp;&nbsp;&nbsp;
    <font color="purple">
    [#list discussTypes as d]
    [#if d.value='${discuss.discussType}']
    ${d.name}&nbsp;&nbsp;&nbsp;
    [/#if]
    [/#list]
    </font>
    <span>
    发表于&nbsp;&nbsp;&nbsp; [#if discuss.time??]${discuss.time!}
    [#else]  ${discuss.createTime}
    [/#if]
    </span>
    </li>
    <li class="pl_txt"> ${discuss.content!} [#if discuss.replay??]<br/>卖家回复：${discuss.replay!}[/#if]
    [#if memberId??]
    [#if discuss.member.id=memberId]&nbsp;&nbsp;&nbsp;更改评论[/#if]
    [/#if]
    </li>
    [/#list]
    [/#if]
    </ul>
    <div class="clear"></div>
	<div class="pageNumber">[@pagination_style sysPage='3'/]</div>
</div>
[/@discuss_page]
</form> 

[#list discussTypes as d]
<div id="tbc_1${d.value}" class="undis">
[@discuss_page productId=product.id count='20' pageNo=pageNo discussType=d.value]
    <div class="pl_line "> 
    <ul class="pl_zone">
    [#if tag_list?size gt 0]
    [#list tag_list as discuss]
    <li><strong>${discuss.member.username!}</strong>&nbsp;&nbsp;&nbsp;&nbsp;
    <span>
    发表于&nbsp;&nbsp;&nbsp; [#if discuss.time??]${discuss.time!}
    [#else]  ${discuss.createTime}
    [/#if]
    </span>
    </li>
    <li class="pl_txt"> ${discuss.content!}[#if discuss.replay??]<br/>卖家回复：${discuss.replay!}[/#if]
    [#if memberId??]
    [#if discuss.member.id=memberId]&nbsp;&nbsp;&nbsp;更改评论[/#if]
    [/#if]
    </li>
    [/#list]
    [/#if]
    </ul>
    <div class="clear"></div>
	<div class="pageNumber">[@pagination_style sysPage='3'/]</div>
</div>
[/@discuss_page]
</div> 
[/#list]
<form id="loginForm" action="${base!}/login.jspx" method="get" target="_top"></form>
</body>
</html>